<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Cache-Control" content="no-siteapp" />
 <link th:href="@{/erp/assets/css/bootstrap.min.css}" rel="stylesheet" />
        <link rel="stylesheet" th:href="@{/erp/css/style.css}"/>
        <link th:href="@{/erp/assets/css/codemirror.css}" rel="stylesheet">
        <link rel="stylesheet" th:href="@{/erp/assets/css/ace.min.css}" />
        <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome.min.css}" />
        	<!--[if IE 7]>
		  <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome-ie7.min.css}" />
		<![endif]-->
        <!--[if lte IE 8]>
		  <link rel="stylesheet" th:href="@{/erp/assets/css/ace-ie.min.css}" />
		 <![endif]-->
		<script th:src="@{/erp/js/jquery-1.9.1.min.js}"></script>
        <script th:src="@{/erp/assets/js/bootstrap.min.js}"></script>
		<script th:src="@{/erp/assets/js/typeahead-bs2.min.js}"></script>
        <script th:src="@{/erp/assets/layer/layer.js}" type="text/javascript" ></script>
        <script th:src="@{/erp/assets/js/jquery-ui-1.10.3.custom.min.js}"></script>
		<script th:src="@{/erp/assets/js/jquery.ui.touch-punch.min.js}"></script>
        <script th:src="@{/erp/assets/js/ace-elements.min.js}"></script>
		<script th:src="@{/erp/assets/js/ace.min.js}"></script>
         <script th:src="@{/erp/assets/js/jquery.dataTables.min.js}"></script>
         <script th:src="@{/erp/assets/js/jquery.dataTables.bootstrap.js}"></script>
<title>激光打印机管理</title>

</head>

<body>

<div class="margin clearfix">
 <div class="stystems_style">
  <div class="tabbable">
  <div class="page-content clearfix">
    <div id="Member_Ratings">
      <!--<div class="d_Confirm_Order_style">
	<ul class="nav nav-tabs" id="myTab">
	  <li class="active">
		 <a data-toggle="tab" href="#home"><i class="green fa fa-home bigger-110"></i>激光打印机管理</a></li>
	</ul>
	</div>-->
	<div class="tab-content">

	  <div id="home" class="tab-pane active">
        <div class="search_style">
      <form >
       <ul class="search_content clearfix">
       <li><label class="l_f">查询打印机：</label><input  type="text" id="no" name="pnum" class="text_add" placeholder="输入打印机编号"  style=" width:400px"/></li>
       <li style="width:90px;"><button type="button" class="btn_search" id="search"><i class="icon-search"></i>查询</button></li>
      </ul>
      </form>
    	</div>

		 <!---->
		<div class="border clearfix">
        <span class="l_f">
         <a href="javascript:" id="member_add" class="btn btn-warning"><i class="icon-plus"></i>添加打印机</a>
        <a href="javascript:" class="btn btn-danger" id="delete"><i class="icon-trash" ></i>批量删除</a>
		</span>
		</div>

         <table class="table table-striped table-bordered table-hover" id="sample-table">
		<thead>
		 <tr>
				<th width="25"><label><input type="checkbox" id="btnAllChk" class="ace"><span class="lbl"></span></label></th>
				<th width="150">打印机编号</th>
				<th width="80">服务器</th>
				<th width="150">描述</th>
                <th width="120">IP地址</th>
				<th width="80">责任产线</th>
				<th width="250">备注</th>
				<th width="250">操作</th>
			</tr>
		</thead>
	<tbody>
    </tbody>
	</table>
  </div>
 </div>
      <!--添加打印机图层-->
<div class="add_menber" id="add_menber_style" style="display:none">

    <ul class=" page-content">
     <li style="position: relative;left: -5px;"><label class="label_name" style="width: 85px;">*打印机编号：</label><span class="add_name"><input value=""   name="打印机编号" type="text"  class="text_add  notnull" id="num"/></span><div class="prompt r_f"></div></li>
	 <li><label class="label_name">*服务器：</label><span class="add_name"><input name="服务器" type="text"  class="text_add  notnull" id="server"  /></span><div class="prompt r_f"></div></li>
	 <li><label class="label_name">描述：</label><span class="add_name"><input name="描述" type="text"  class="text_add" id="desecibe"/></span><div class="prompt r_f"></div></li>

    </select></span><div class="prompt r_f"></div></li>
     <div class="prompt r_f"></div>
     </li>
     <li><label class="label_name">*IP地址：</label><span class="add_name"><input name="IP地址" type="text"  class="text_add  notnull" id="address" /></span><div class="prompt r_f"></div></li>



        <li><label class="label_name">*责任产线：</label><span class="add_name ">
         <select id="line" class="notnull" name="责任产线">
         <option value="">请选择产线</option>
         </select>
     </span><div class="prompt r_f"></div></li>




     <li class="adderss"><label class="label_name">备注：</label><span class="add_name"><input name="备注" type="text"  id="remake" class="text_add" style=" width:350px"/></span><div class="prompt r_f"></div></li>
    </ul>
 </div>
  <!--编辑打印机图层-->
<div class="add_menber" id="add_menber_styl" style="display:none">

    <ul class=" page-content">
     <li style="position: relative;left: -5px;"><label class="label_name" style="width: 85px;">*打印机编号：</label><span class="add_name"><input  name="打印机编号" type="text"  class="text_add notnull1" id="upnum"/></span><div class="prompt r_f"></div></li>
	 <li><label class="label_name">*服务器：</label><span class="add_name"><input  name="服务器" type="text"  class="text_add notnull1" id="upserver"/></span><div class="prompt r_f"></div></li>
	 <li><label class="label_name">描述：</label><span class="add_name"><input  name="描述" type="text"  class="text_add" id="updescribe"/></span><div class="prompt r_f"></div></li>
        <div class="prompt r_f"></div>
     </li>
     <li><label class="label_name">*IP地址：</label><span class="add_name"><input  name="IP地址" type="text"  class="text_add notnull1" id="upip"/></span><div class="prompt r_f"></div></li>


     <li><label class="label_name">*责任产线：</label><span class="add_name ">
         <select id="upline" class="notnull1" name="责任产线">
         <option value="">请选择产线</option>
         </select>
     </span><div class="prompt r_f"></div></li>





        <li class="adderss"><label class="label_name">备注：</label><span class="add_name"><input  name="备注" type="text"  class="text_add" style=" width:350px" id="upremake"/></span><div class="prompt r_f"></div></li>
    </ul>
 </div>
 </div>
		</div>
		</div>
 </div>
</div>
</body>
</html>
<script>



    $(function () {
        var table = $('#sample-table').dataTable({
            "autoWidth": false,//当重复刷新表格时，我的页面会出现变形的，现象，加了这个就好了
            searching: false,
            serverSide: true,   //开始服务器分页
            destroy:true,
            ajax: {
                url: '/printer/find',
                type: 'get',
                data: function (d) {
                    var data = $('form').serialize();   //获取查询条件

                    //获取分页信息
                    var searchParams = {
                        start: d.start,
                        length: d.length,
                    };
                    data = data + '&' + $.param(searchParams);
                    return data;
                }
            },


            columnDefs: [{"defaultContent": "",
                "targets": "_all"}],
            columns: [
                {
                    "data": "id", "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).empty().append('<label><input type="checkbox" value="' + rowData.id + '" id="ID" name="yy"  class="ace"><span\n' +
                            '                                            class="lbl"></span></label>');
                    }
                },
                {"data": "p_num"},
                {"data": "p_server"},
                {"data": "p_describe"},
                {"data": "p_ip"},
                {"data": "p_line"},
                {
                    "data": "p_remark"},
                {

                    "data": "laser_code", "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).empty().append('  <a title="编辑" onclick="member_edit(this)" href="javascript:;"  class="btn btn-xs btn-info" ><i class="icon-edit bigger-120"></i></a>\n' +
                                '                <a title="删除" href="javascript:;"  onclick="member_del(this,\'1\')" class="btn btn-xs btn-warning" ><i class="icon-trash  bigger-120"></i></a>');

                    }
                },
            ]
        });
        //搜索按钮事件
        $('#search').click(function () {
            table.fnUpdate();
        })

    })



    /*添加打印机编号的正则表达式*/
      $('#num').on('blur',function () {
          console.log( $('#num').val())
          if(!(/^[\u4E00-\u9FA5A-Za-z0-9]{2,20}$/.test($('#num').val()))){
              $('#num').val("");
              alert("打印机编号有误，请重填");
              return false;
          }else {
              return true;
          }
      })



    $('#upnum').on('blur',function () {

        console.log( $('#num').val())
        if(!(/^[\u4E00-\u9FA5A-Za-z0-9]{2,20}$/.test($('#upnum').val()))){

            $('#upnum').val("");
            alert("打印机编号有误，请重填");
            return false;
        }else {
            return true;
        }
    })

     $('#address').on('blur',function () {
         if (!/^(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])$/.test($('#address').val())){
             $('#address').val("");
              alert("ip地址有误，请重填");
             return false;
         }
         else {
             return true;
         }
     })

    $('#upip').on('blur',function () {
        if (!/^(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])$/.test($('#upip').val())){
            $('#upip').val("");
            alert("ip地址有误，请重填");
            return false;
        }
        else {
            return true;
        }
    })

    /*打印机-添加*/
 $('#member_add').on('click', function(){
    layer.open({
        type: 1,
        title: '添加激光打印机',
		maxmin: true,
		shadeClose: true, //点击遮罩关闭层
        area : ['800px' , ''],
        content:$('#add_menber_style'),
		btn:['提交','取消'],
		yes:function(index,layero) {
            var num = 0;
            var str = "";

            $('.notnull').each(function (n) {
                if ($(this).val() == "") {

                    layer.alert(str += "" + $(this).attr("name") + "不能为空！\r\n", {
                        title: '提示框',
                        icon: 0,
                    });
                    num++;
                    return false;
                }

            })
            if (num > 0) {
                return false;
            } else {
                $.ajax({
                    url: '/printer/add',
                    data: {
                        "pNum": $("#num").val()
                        , "pServer": $("#server").val()
                        , "pDescribe": $("#desecibe").val()
                        , "pIp": $("#address").val()
                        , "pLine": $("#line").val()
                        , "pRemark": $("#remake").val()
                    },
                    type: 'post',
                    dataType: 'json',
                    success: function (data) {
                        if (data.rs) {
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 2000});
                        }
                    }
                });
                layer.alert('添加成功！', {
                    title: '提示框',
                    icon: 1,
                });
                layer.close(index);
                window.parent.document.getElementById('iframe').contentWindow.location.reload(true);
            }
        }
    });
});


    $.ajax({
        url: '/printer/allline',
        success:function (d) {
            if(d.rs){
                var data = d.data;
                for (var i in data) {

                    $('#upline:last').append("<option value="+data[i].productionName+">"+data[i].productionName+"</option>")

                    $('#line:last').append("<option value="+data[i].productionName+">"+data[i].productionName+"</option>>")
                }
            }else {
                layer.msg(data.msg, {icon: 2, time: 2000});
            }
        }
    });


     $('#num').on('change',function () {
         $.ajax({
             url:'/printer/getname',
             type:'get',
              data:{
                 pNum:$('#num').val()
             },
             success:function (d) {
                 if (d.rs) {
                     var data = d.data;
                     if (data!= null) {
                         alert("打印机编号已存在！")
                         window.parent.document.getElementById('iframe').contentWindow.location.reload(true);
                     }
                 }
             else {
                     layer.msg(data.msg, {icon: 2, time: 2000});
                 }
             }
         })

     })

/*打印机-编辑*/
function member_edit(id){
    var aa = $(id).parent().parent().find("td:eq(0)").find("label").find("input").val()

     $.ajax({
         url : '/printer/update',
         type : 'post',
         dataType : 'json',
         data : {
             id : aa
         },
         success : function (d) {
             if (d.rs){
                 var data = d.data;
              $('#upnum').val(data.pnum)
              $('#upserver').val(data.pserver)
              $('#updescribe').val(data.pdescribe)
              $('#upip').val(data.pip)
              $('#upline').val(data.pLine)
              $('#upremake').val(data.premark)
             }
         else {
                 layer.msg(data.msg, {icon: 2, time: 2000});
             }
         }


     })
	  layer.open({
        type: 1,
        title: '修改激光打印机信息',
		maxmin: true,
		shadeClose:false, //点击遮罩关闭层
        area : ['800px' , ''],
        content:$('#add_menber_styl'),
		btn:['提交','取消'],
		yes:function(index,layero){
		 var num=0;
		 var str="";

         $('.notnull1').each(function (n) {
             if ($(this).val() == "") {

                 layer.alert(str += "" + $(this).attr("name") + "不能为空！\r\n", {
                     title: '提示框',
                     icon: 0,
                 });
                 num++;
                 return false;
             }


		 });
		  if(num>0){  return false;}
          else{
              console.log(aa);
              $.ajax({
                  url: '/printer/update1',
                  data: {
                         id:aa
                      , "pNum": $("#upnum").val()
                      , "pServer": $("#upserver").val()
                      , "pDescribe": $("#updescribe").val()
                      , "pIp": $("#upip").val()
                      , "pLine": $("#upline").val()
                      , "pRemark": $("#upremake").val()
                  },
                  type: 'post',
                  dataType: 'json',
                  success: function (data) {
                     if (data.rs){

                     }else {
                         layer.msg(data.msg, {icon: 2, time: 2000});
                     }

                  }
              })

			  layer.alert('添加成功！',{
               title: '提示框',
		    	icon:1,
			  });
			   layer.close(index);
              window.parent.document.getElementById('iframe').contentWindow.location.reload(true);
		  }
		}
    });
}
/*打印机-删除*/
function member_del(obj,id){


        layer.confirm('确认要删除吗？',function(index){
            var ids = $(obj).parent().parent().find("td:eq(0)").find("label").find("input").val()
            console.log(ids)
            $.ajax({
                url:'/printer/delete',
                type:'post',
                dataType:'json',
                data : {id: ids},
                success:function (data) {
                    if (data.rs){

                    }else {
                        layer.msg(data.msg, {icon: 2, time: 2000});
                    }
                }
            })


            $(obj).parents("tr").remove();
		    layer.msg('已删除!',{icon:1,time:1000});
            window.parent.document.getElementById('iframe').contentWindow.location.reload(true);
	});
}
$(function () {



    //全选
    $("#btnAllChk").click(function () {
      
        $(".ace:eq(1)").prop("checked", true);

     });


     //反选

   /*  $("#btnInvert").click(function () {

          $("#chk input:checkbox").each(function () {

            this.checked = !this.checked;

         })
    });*/

})
    /**
     * 多删
     */
    $("#delete").click(function () {

        var abc = [];

        //定义一个空数组
        $("input[name='yy']:checked").each(function (i) {    //把所有被选中的复选框的值存入数组
            abc[i] = $(this).val();
        });

           $.ajax({
               url:'/printer/deletes',
               type:'post',
               dataType:'json',
               contentType : "application/json;charsetset=UTF-8",
               data : JSON.stringify(abc),
              success:function (data) {
                  if (data.rs){

                  }else {
                      layer.msg(data.msg, {icon: 2, time: 2000});
                  }
              }
           })


         window.parent.document.getElementById('iframe').contentWindow.location.reload(true);
    })
</script>
